package com.example.family_sec;

import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;


// 用户的设置信息
public class SettingActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        Switch sw_buzzer = findViewById(R.id.sw_buzzer);
        Switch sw_notification = findViewById(R.id.sw_notification);

        Settings settings = new Settings();

        SharedPreferences sp = getSharedPreferences("settings", MODE_PRIVATE);
        boolean buzzer = sp.getBoolean("buzzer", false);
        boolean notification = sp.getBoolean("notification", false);
        settings.setBuzzer(buzzer);
        settings.setUnNotification(notification);

        // ...
        //
        sw_buzzer.setChecked(buzzer);
        sw_notification.setChecked(notification);
        sw_buzzer.setOnCheckedChangeListener((buttonView, isChecked) -> {

            Toast.makeText(buttonView.getContext(), "checked " + isChecked, Toast.LENGTH_SHORT).show();

            sp.edit().putBoolean("buzzer",isChecked).apply();
            // todo ....提交服务器用户关闭蜂鸣器的警报的异常信息处理.
        });

        sw_notification.setOnCheckedChangeListener(((buttonView, isChecked) -> {
            sp.edit().putBoolean("notification",isChecked).apply();
        }));
    }
}
